﻿@model CategoryListModel
@inject AdminAreaSettings adminAreaSettings

@{
    //page title
    ViewBag.Title = T("Admin.Catalog.Categories.Manage").Text;
}

<div class="row">
    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption">
                    <i class="fa fa-sitemap"></i>
                    @T("Admin.Catalog.Categories.Manage")
                    <small>@Html.ActionLink("(" + T("Admin.Catalog.Categories.SwitchToTreeView") + ")", "Tree")</small>
                </div>
                <div class="actions btn-group btn-group-devided util-btn-margin-bottom-5">
                    <a href="@Url.Action("Create")" class="btn green"><i class="fa fa-plus"></i><span class="hidden-xs"> @T("Admin.Common.AddNew") </span></a>
                    <a href="@Url.Action("ExportXml")" class="btn default">
                        <i class="fa fa-file-code-o"></i> @T("Admin.Common.ExportToXml")
                    </a>
                    <a href="@Url.Action("ExportXlsx")" class="btn default">
                        <i class="fa fa-file-excel-o"></i> @T("Admin.Common.ExportToExcel")
                    </a>
                    <button type="button" name="importexcel" id="importexcel" class="btn blue">
                        <i class="fa fa-upload"></i>
                        @T("Admin.Common.ImportFromExcel")
                    </button>
                    <vc:admin-widget widget-zone="category_list_buttons" additional-data="null" />
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="form-group">
                            <admin-label asp-for="SearchCategoryName" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="SearchCategoryName" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="SearchStoreId" />
                            <div class="col-md-4 col-sm-6">
                                <admin-select asp-for="SearchStoreId" asp-items="Model.AvailableStores" />
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <div class="row">
                            <div class="col-md-offset-3 col-sm-offset-3 col-md-9 col-sm-9">
                                <button class="btn btn-success filter-submit" id="search-categories">
                                    <i class="fa fa-search"></i> @T("Admin.Common.Search")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="x_content">
                <div id="categories-grid"></div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#categories-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("List", "Category"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(adminAreaSettings.DefaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(adminAreaSettings.GridPageSizes)]
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "Breadcrumb",
                title: "@T("Admin.Catalog.Categories.Fields.Name")",
                template: '<a class="k-link" href="Edit/#=Id#">#=kendo.htmlEncode(Breadcrumb)#</a>',
            },
            {
                field: "ShowOnHomePage",
                title: "@T("Admin.Catalog.Categories.Fields.ShowOnHomePage")",
                width: 100,
                minScreenWidth: 750,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(ShowOnHomePage) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
            },
            {
                field: "IncludeInTopMenu",
                title: "@T("Admin.Catalog.Categories.Fields.IncludeInTopMenu")",
                width: 100,
                minScreenWidth: 750,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(IncludeInTopMenu) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
            },
            {
                field: "Published",
                title: "@T("Admin.Catalog.Categories.Fields.Published")",
                width: 100,
                minScreenWidth: 500,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(Published) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
            }, {
                field: "DisplayOrder",
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                title: "@T("Admin.Catalog.Categories.Fields.DisplayOrder")",
                width: 100,    
                minScreenWidth: 750,
            }]
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        //search button
        $('#search-categories').click(function () {
            //search
            var grid = $('#categories-grid').data('kendoGrid');
            grid.dataSource.page(1); //new search. Set page size to 1
            //grid.dataSource.read(); we already loaded the grid above using "page" function
            return false;
        });

        $("#@Html.FieldIdFor(model => model.SearchCategoryName)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-categories").click();
                return false;
            }
        });
    });

    function additionalData() {
        var data = {
            SearchCategoryName: $('#@Html.FieldIdFor(model => model.SearchCategoryName)').val(),
            SearchStoreId: $('#SearchStoreId').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
</script>
@*import categories form*@
<div class="modal-dialog" id="importexcel-window" style="display:none; padding: 0 10px;">
    <form asp-controller="Category" asp-action="ImportFromXlsx" method="post" enctype="multipart/form-data">
        
        <em>@T("Admin.Catalog.Category.List.ImportFromExcelTip")</em>
        <div class="form-group">
            &nbsp;
        </div>
        <div class="form-group">
            <div class="col-md-3" style="margin-top: 2px; height: 34px; padding-left: 25px;">
                <label class="control-label">
                    @T("Admin.Common.ExcelFile"):
                </label>
            </div>
            <div class="col-md-9">
                <input type="file" id="importexcelfile" name="importexcelfile" />
            </div>
        </div>
        <div class="form-group">
            &nbsp;
        </div>
        <div class="form-group">
            <div class="col-md-2">
                &nbsp;
            </div>
            <div class="col-md-10 text-right mt-10">
                <input type="submit" class="k-button" value="@T("Admin.Common.ImportFromExcel")" />
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            $("#importexcel").click(function (e) {
                e.preventDefault();
                var window = $("#importexcel-window");
                if (!window.data("kendoWindow")) {
                    window.kendoWindow({
                        modal: true,
                        title: "@T("Admin.Common.ImportFromExcel")",
                        actions: ["Close"]
                    });
                }
                window.data('kendoWindow').center().open();
            });

        });
</script>
